#include <queue>
using std::queue;
#include "nb_msg.h"
#include "nb_lock.h"
#include "spthreadpool.h"

typedef void (*DispatchFunc)(NB_Request * lpRequest, NB_Response * lpResponse);

class NB_Server;
class NB_Handle
{
public:
	NB_Handle(int nMaxThreads = 2);
	~NB_Handle();
	bool Start();

private:
	bool GetInMsg(NB_Msg * msg);
	void SetInMsg(NB_Msg * lpMsg);

	bool GetOutMsg(NB_Msg * msg);
	void SetOutMsg(NB_Msg * lpMsg);

	static DWORD WINAPI WorkerThread(void * lParam);

private:
	DispatchFunc	m_DispatchFunc;
	NB_Request *	m_lpRequest;
	NB_Response *	m_lpResponse;

	bool			m_bShutdown;
	queue<NB_Msg>	m_InMsgQueue;
	queue<NB_Msg>	m_OutMsgQueue;
	CsLock *		m_CsLock;

	SP_ThreadPool * m_ThreadPool;

	friend class NB_Server;
};